<!-- 导入记录 -->
<template>
  <div class='import_log'>
    <Table class="tab" :loading="loading" ref="TableHeight" max-height="300" :columns="columns"
      :data="tableData"></Table>
    <!-- 分页 -->
    <page :pageData='pageData' @pageOnChangeFun='pageOnChangeFun'
      @pageOnPageSizeChangeFun='pageOnPageSizeChangeFun' :isShowTotalCount='false'
      :showElevator='false'></page>
  </div>
</template>

<script>
  import deliveryMgr from '@/biz/delivery/control'
  export default {
    components: {},
    data() {
      return {
        columns: [
        {
          title: '导入类型',
          key: 'documentName',
          minWidth: 130,
        },
        {
          title: '导入状态',
          key: 'importStatusStr',
          minWidth: 130,
        },
        {
          title: '导入时间',
          key: 'updateTime',
          minWidth: 150,
          render: (h, params) => {
            return h(
              'div',
              params.row.importStatus == 2 ? params.row.updateTime : '-'
            )
          },
        },
        {
          title: '导入结果',
          minWidth: 120,
          render: (h, params) => {
            return h('div', [
              h(
                'a',
                {
                  style: {
                    padding: '0 6px',
                    display: params.row.importStatus == 2 &&
                      params.row.operateStatus != 1 ?
                      'block' : 'none',
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      this.onload(params.row)
                    },
                  },
                },
                '下载'
              ),
            ])
          },
        }, ],
        tableData: [],
        loading: false,
        pageData: {
          total: 0,
          current: 1,
          rows: 10,
          pageSizeOpts: [10, 20, 30, 40, 50],
        },
        housesId: this.$dt.buildInfo().housesId,
      }
    },
    methods: {
      init() {
        let params = {
          housesId: this.housesId,
          page: this.pageData.current,
          rows: this.pageData.rows,
        }
        deliveryMgr
          .selectImportRecordsListData(params)
          .then((res) => {
            if (res) {
              this.tableData = res.list
              this.pageData.total = res.total
            } else {
              this.tableData = []
              this.pageData.total = 0
            }
            this.loading = false
          })
          .catch((res) => {
            this.pageData.total = 0
            this.loading = false
          })
      },
      //分页触发
      pageOnChangeFun() {
        this.init(this.orgId, this.formValidate)
      },
      //改变每页条数触发
      pageOnPageSizeChangeFun(rows) {
        this.init(this.orgId, this.formValidate)
      },
      //下载
      onload(rows) {
        let params = {
          id: rows.id,
        }
        deliveryMgr.exportImportRecord(params).then((res) => {
          this.$emit('onClose')
          this.$store.dispatch('downloadModelFlag', true)
        })
      },
    },
    mounted() {
      this.init()
    },
  }
</script>
<style lang='scss' scoped>
</style>